package com.sam.widget.headerBar;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;

import com.sam.widget.R;

/**
 * Created by Administrator on 2016/6/13.
 */
public class LeftImgTitleRightImgBar extends LeftImgTitleBar{
    private Drawable rightImgSrcDrawable,rightImgBgDrawable;
    private ImageView rightImg;

    public LeftImgTitleRightImgBar(Context context) {
        this(context,null);
    }

    public LeftImgTitleRightImgBar(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public LeftImgTitleRightImgBar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    protected void getAttrs(AttributeSet attrs) {
        super.getAttrs(attrs);
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.LeftImgTitleRightImgBar);
        rightImgSrcDrawable = ta.getDrawable(R.styleable.LeftImgTitleRightImgBar_rightImgSrcDrawable);
        rightImgBgDrawable = ta.getDrawable(R.styleable.LeftImgTitleRightImgBar_rightImgBgDrawable);
        ta.recycle();
    }

    @Override
    protected void findView() {
        super.findView();
        if(rightImgSrcDrawable == null && rightImgBgDrawable == null) return;
        rightImg = new ImageView(context);
        if(rightImgSrcDrawable != null) rightImg.setImageDrawable(rightImgSrcDrawable);
        if(rightImgBgDrawable != null) rightImg.setBackgroundDrawable(rightImgBgDrawable);
    }

    @Override
    public View getRightView() {
        return rightImg;
    }
}
